package com.groupsix.service.impl;

import com.groupsix.entity.Class;
import com.groupsix.mapper.ClassMapper;
import com.groupsix.service.ClassService;
import com.groupsix.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 董盛昌
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 班级业务逻辑接口实现类
 * @date 2021/10/17 16:30
 */
@Service
public class ClassServiceImpl implements ClassService {

    // classDao
    @Autowired
    private ClassMapper classMapper;


    //分页查询
    @Override
    public PageInfo findPageInfo(String cClassname, String cCounsellor, Integer cClassid, Integer pageIndex, Integer pageSize) {
        PageInfo pi = new PageInfo();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = classMapper.totalCount(cClassname,cClassid,cCounsellor);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //每一页显示班级信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Class> classList =	classMapper.getClassList(cClassname,cClassid,cCounsellor,
                    (pi.getPageIndex()-1)*pi.getPageSize(),pi.getPageSize());
            pi.setList(classList);
        }
        return pi;
    }

    @Override
    public List<Class> getAll(){
        List<Class> classList = classMapper.getAll();
        return  classList;
    }

    //通过id删除班级信息
    @Override
    public int deleteClass(Integer c_id) {
        return classMapper.deleteClass(c_id);
    }

    //添加班级信息
    @Override
    public int addClass(Class uclass) {
        return classMapper.addClass(uclass);
    }

    @Override
    public Class findClassById (Integer cId){
        Class c = classMapper.findClassById(cId);
        return  c;
    }
    //修改班级信息
    @Override
    public int updateClass(Class uclass) {
        return classMapper.updateClass(uclass);
    }

    //查询宿舍人员信息
    @Override
    public List<Class> findClassStudent(Class uclass) {
        List<Class> c = classMapper.findClassStudent(uclass);
        return c;
    }

}
